package com.otree.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import com.otree.entity.SysOssEntity;
import com.otree.service.SysOssService;
import com.otree.utils.PageUtils;
import com.otree.utils.R;


/**
 * 文件上传
 *
 * @author forest
 * @email 123@163.com
 * @date 2018-01-24 11:00:46
 */
@Controller
@RequestMapping("/sys/oss")
public class SysOssController {
	@Autowired
	private SysOssService sysOssService;

	@RequestMapping("/sysoss.html")
	public String list(){
		return "sys/sysoss.html";
	}

	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("sys:oss:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);

		//查询列表数据
		List<SysOssEntity> sysOssList = sysOssService.queryList(map);
		int total = sysOssService.queryTotal(map);

		PageUtils pageUtil = new PageUtils(sysOssList, total, limit, page);

		return R.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:oss:info")
	public R info(@PathVariable("id") Long id){
		SysOssEntity sysOss = sysOssService.queryObject(id);

		return R.ok().put("sysOss", sysOss);
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("sys:oss:save")
	public R save(@RequestBody SysOssEntity sysOss){
		sysOssService.save(sysOss);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sys:oss:update")
	public R update(@RequestBody SysOssEntity sysOss){
		sysOssService.update(sysOss);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("sys:oss:delete")
	public R delete(@RequestBody Long[] ids){
		sysOssService.deleteBatch(ids);

		return R.ok();
	}

}
